﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace iNet.Media.Imaging
{
	/// <summary>
	/// NEF 影像解碼工作工廠。
	/// </summary>
	public class NefImageDecodeTaskFactory : FastImageDecodeTaskFactory
	{
		#region 建構子
		/// <summary>
		/// 初始化新的 NefImageDecodeTaskFactory 執行個體。
		/// </summary>
		public NefImageDecodeTaskFactory()
			: base("NEF Image DecodeTask Factory", ImageFormats.Nef)
		{ }
		#endregion
		#region CreateDecodeTask
		public override MediaDecodeTask CreateDecodeTask(MediaStorage source)
		{
			return new NefImageDecodeTask(source);
		}
		#endregion
		#region IsSupportedFormatCore
		protected override bool IsSupportedFormatCore(byte[] mediaHeader)
		{
			if (mediaHeader.Length < 4)
				return false;
			if (mediaHeader[0] != mediaHeader[1] || (mediaHeader[0] != 'I' && mediaHeader[0] != 'M'))
				return false;
			BitConverter converter = (mediaHeader[0] == 'I' ? BitConverter.LittleEndian : BitConverter.BigEndian);
			if (converter.ToUInt16(mediaHeader, 2) != 0x2a)
				return false;
			return true;
		}
		#endregion
		#region MediaHeaderSize
		public override int MediaHeaderSize
		{
			get
			{
				return 4;
			}
		}
		#endregion
	}
}
